part of YFree;

///YFree启动函数
void yRunApp(YPage page, MaterialColor primarySwatch, {required onYConfig(), ThemeData? theme}) {
  onYConfig();
  FlutterError.onError = (FlutterErrorDetails details) => yDoCrash(details);
  final textStyle = TextStyle(color: Colors.black, fontSize: 14);
  var yThemeData = ThemeData(primarySwatch: primarySwatch);
  yThemeData = yThemeData.copyWith(
    platform: TargetPlatform.android,
    primaryColor: YConfig.themeColor,
    textTheme: yThemeData.textTheme.copyWith(bodyText1: textStyle, bodyText2: textStyle, button: textStyle, caption: textStyle, overline: textStyle),
    colorScheme: yThemeData.colorScheme.copyWith(secondary: YConfig.themeColor),
  );
  runZonedGuarded(() {
    runApp(MaterialApp(
      title: YConfig.appName,
      debugShowCheckedModeBanner: YConfig.DEBUG,
      theme: theme ?? yThemeData,
      localizationsDelegates: [
        GlobalMaterialLocalizations.delegate,
        GlobalWidgetsLocalizations.delegate,
        ChineseCupertinoLocalizations.delegate,
      ],
      localeResolutionCallback: (locale, supportedLocales) {
        YConfig.onLocale(locale, supportedLocales);
        return locale;
      },
      supportedLocales: [Locale("zh", "CH")],
      navigatorObservers: [BotToastNavigatorObserver()],
      builder: (context, child) {
        final botToastBuilder = BotToastInit();
        return botToastBuilder(context, child);
      },
      home: YStatefulWidget(() => page),
    ));
  }, (Object obj, StackTrace stack) => yDoCrash(stack));
  yPages.add(page);
}
